package com.hnl.action.activity;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.HNLPageDispatch;
import com.hnl.core.aware.HNLAuthAware;
import com.hnl.core.aware.HNLTalentAware;
import com.hnl.core.aware.MiscTypeAware;
import com.hnl.dao.ActivityDAO;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;

@SuppressWarnings("serial")
public class DeleteActivity extends HttpServlet implements HNLAuthAware,
		HNLTalentAware, MiscTypeAware, HNLPageDispatch {
	public static final Logger LOG = LoggerFactory.getLogger(DeleteActivity.class);

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try {
			String talentID = req.getParameter(ATTRIBUTE_TALENT_ID);
			String[] selectedCheckboxs = req
					.getParameterValues("tableCheckbox");

			ActivityDAO activityDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getActivityDAO();
			for (String actID : selectedCheckboxs) {
				activityDAO.delActivity(Integer.valueOf(actID));
			}

			req.setAttribute(ATTRIBUTE_TALENT_ID, talentID);
			req.setAttribute(ATTRIBUTE_TAB_ID, ATTRIBUTE_ACTIVITY_INFO_TAB_ID);

			RequestDispatcher dispatcher = req
					.getRequestDispatcher(TALENT_INFO_PAGE);
			dispatcher.forward(req, resp);
		} catch (DAOException e) {
			LOG.error("Error to delete Activity", e);
		}
	}

}
